home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / applications / wp / mced-1.1.lha / CEDScripts / Stats.ced < prev    next >
Encoding:
Text File  |  1992-09-02  |  2.7 KB  |  83 lines

  1. /*
  2. **    Stat.ced
  3. **    
  4. **    $VER: Stat.ced 1.4 (14.1.95)
  5. **    
  6. **    This scripts displays current file's statistics: number of chars, lines,
  7. **    words and sentences. ARexx'es definition of word is used, not CEd's.
  8. **    Sentences are counted by checking number of '.', '!' and '?' chars.
  9. **    This script works much faster than ASDG's Word-Count-File.ced.
  10. **    To get statistics for whole file just call this script. To get statistics
  11. **    for part of file, mark a block and call this macro.
  12. **    See docs for more details.
  13. **    
  14. **    This script requires CygnusEd Professional v3.5 (or later) to run.
  15. **    
  16. **    Copyright © 1995 Michael Letowski
  17. */
  18.  
  19. /* Get host */
  20. PARSE SOURCE com res called resolved ext host .
  21. IF host="REXX" THEN                                                /* From command line */
  22.     ADDRESS "rexx_ced"                                            /* Talk to default ced */
  23.  
  24. OPTIONS RESULTS                                                        /* Enable results from commands */
  25.  
  26. LF='0A'X                                                                    /* Simple constant */
  27.  
  28. 'Status CURSORCOLUMN'                                            /* Get cursor horizontal... */
  29. Column=RESULT+1
  30. 'Status CURSORLINE'                                                /* ... and vertical position */
  31. Line=RESULT+1
  32.  
  33. 'DM "Copying to clipboard..."'                        /* Let the user know what's going on */
  34.  
  35. 'Copy block'                                                            /* Something selected yet? */
  36. IF ~RESULT THEN
  37. DO
  38.     'Beg of file'                                                        /* Copy whole file to clipboard */
  39.     'Mark block'
  40.     'End of file'
  41.     'Copy block'
  42. END
  43.  
  44. 'LL' Line Column                                                    /* Move cursor to old position */
  45. 'DM "Counting..."'                                                /* Change status bar again */
  46.  
  47. 'Status RESTNAME'                                                    /* Get file name */
  48. FileName=RESULT
  49. 'Status BLOCKBUFFER'                                            /* Get text from clipboard */
  50. Res=RESULT
  51.  
  52. WordsInText=Words(Res)                                        /* Count words */
  53. TotalLen=Length(Res)                                            /* Calculate size of buffer */
  54. StripLen=Length(Compress(Res,".!?"))            /* Delete punctuations from text */
  55. LinesLen=Length(Compress(Res,LF))                    /* Delete LFs from text */
  56. Sentences=TotalLen-StripLen                                /* Substract to get number of sentences */
  57. FileLines=TotalLen-LinesLen+1                            /* Substract to get number of lines */
  58.  
  59. IF TotalLen=1 THEN TotalLen=TotalLen "char"
  60. ELSE TotalLen=TotalLen "chars"
  61.  
  62. IF FileLines=1 THEN FileLines=FileLines "line"
  63. ELSE FileLines=FileLines "lines"
  64.  
  65. IF WordsInText=1 THEN WordsInText=WordsInText "word"
  66. ELSE WordsInText=WordsInText "words"
  67.  
  68. IF Sentences=1 THEN Sentences=Sentences "sentence"
  69. ELSE Sentences=Sentences "sentences"
  70.  
  71. Header="Text statistics for" "'"FileName"':"
  72. HdrLen=Length(Header)
  73. OutputText=Header||LF
  74. OutputText=OutputText||CENTRE(TotalLen,HdrLen)||LF
  75. OutputText=OutputText||CENTRE(FileLines,HdrLen)||LF
  76. OutputText=OutputText||CENTRE(WordsInText,HdrLen)||LF
  77. OutputText=OutputText||CENTRE(Sentences,HdrLen)
  78.  
  79. 'Okay1' OutputText                                                /* Present results to user */
  80. 'DM'                                                                            /* Restore status line */
  81.  
  82. EXIT
  83.